Array constructors are lists of values that you can use to
specify an array value.
Syntax:
[[data-type]] [ [[{{{component | component-subrange}},... :
component-value};... ]] [[OTHERWISE component-value [[;]] ]] ]
The 'data-type' specifies the constructor's data type. If you
use the constructor in the executable section or in the CONST
section, a data-type identifier is required. Do not use a type
identifier in initial-state specifiers elsewhere in the
declaration section or in nested constructors.
The 'component' or a 'component-subrange' specifies an element
number to which the component-value applies. You can specify a
subrange of components. Array elements do not have to be
specified in order. The component must be a compile-time value
or constant.
The 'component-value' specifies the value to be assigned to the
array elements in the component-list; the value must be of the
same data type as the array-component type. This value is a
compile-time value; if you use the constructor in the executable
section, you can also use a run-time value.
'OTHERWISE' specifies a value to be assigned to all array
elements that have not already been assigned values.
When using array constructors, you must initialize all elements
of the array; you cannot partially initialize the array.
When you specify constructors for multidimensional arrays in the
executable section, only specify the type of the outermost
array.
1 – Examples
The following examples show possible constructors for the array
Numbers:
VAR
Numbers : Count VALUE [1..3,5 : 1; 4,6 : 2; 7..9 : 3; 10 : 6];
{or, in the executable section}
Numbers := Count[1..3,5 : 1; 4,6 : 2; 7..9 : 3; 10 : x+3];
These constructors give the first, second, third, and fifth
component the value 1; the fourth and sixth component the value
2; and the seventh, eighth, and ninth components the value 3.
The first constructor gives the tenth component the value 6; the
second constructor, since it is in the executable section, can
assign the run-time value x+3 to the tenth component.
Numbers := Count[4,6 : 2; 7..9 : 3; 10 : x+3; OTHERWISE 1];
To specify constructor values for all remaining elements, you
can use the OTHERWISE clause.